package com.syy.homework1;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class HomeWork implements WritableComparable<HomeWork> {
    private String name;
    private Integer number;
    private String numbers;

    public String getNumbers() {
        return numbers;
    }

    public void setNumbers(String numbers) {
        this.numbers = numbers;
    }

    public HomeWork(String name, Integer number, String numbers) {
        this.name = name;
        this.number = number;
        this.numbers = numbers;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public HomeWork() {
    }

    @Override
    public int compareTo(HomeWork o) {
        if (o.getName().equals(this.getName())){
            return this.getNumber().compareTo(o.getNumber());
        }else {
            return this.getName().compareTo(o.getName());
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(name);
        dataOutput.writeUTF(numbers);
        dataOutput.writeInt(number);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.name = dataInput.readUTF();
        this.numbers = dataInput.readUTF();
        this.number = dataInput.readInt();
    }

    @Override
    public String toString() {
        return name + " " + numbers;
    }
}
